<template>
    <view>
        <view v-if="isLoad === null" class="margin-top load notexist text-l load-project"></view>
        <view v-if="isLoad === false" class="margin-top load loading text-l load-project"></view>

        <block v-if="isLoad">
            <view class="main padding-project">
                <view class="article-box margin-top-xs">
                    <!-- article content begin -->
                    <view class="article card-project shadow-project">
                        <view class="title">
                            <text :user-select="true">{{ news.title }}</text>
                        </view>
                        <view class="time">{{ news.createdTime }} {{ news.typeDesc }}</view>

                        <block v-for="(item, index) in news.formContents" :key="index">
                            <view class="content" v-if="item.type == 'text'">
                                <text :user-select="true">{{ item.val }}</text>
                            </view>

                            <view class="pics" v-if="item.type == 'img'">
                                <image
                                    @tap="url"
                                    data-type="img"
                                    :data-url="item.val"
                                    :show-menu-by-longpress="true"
                                    class="loading"
                                    mode="widthFix"
                                    :lazy-load="true"
                                    :src="item.val"
                                ></image>
                            </view>
                        </block>
                        <!-- article content end -->
                    </view>
                    <!-- article content end -->
                </view>
            </view>

            <cmpt-detail
                mode="mode1"
                :topBtnShow="topBtnShow"
                :oid="news.id"
                cate=3
                :title="news.title"
                cover="https://nimg.ws.126.net/?url=http%3A%2F%2Fcms-bucket.ws.126.net%2F2025%2F0829%2F0e71f7a2p00t1qwoh002gc000hf00bnc.png&thumbnail=660x2147483647&quality=80&type=jpg"
                :qr="news.qrCode"
                desc="查看详情"
                :bg="skin.PROJECT_COLOR"
            ></cmpt-detail>
        </block>
    </view>
</template>

<script>
import { mapState } from 'vuex';
const ProjectBiz = require('@/utils/biz/project_biz.js');
const NewsBiz = require('@/utils/biz/news_biz.js');
import cmptDetail from '@/cmpts/biz/detail/detail_cmpt';
const api = require('@/api/api.js'); 
const FootBiz = require('@/utils/comm/biz/foot_biz.js');
const pageHelper = require('@/utils/helper/page_helper.js');

export default {
        components: {
        cmptDetail
    },
    data() {
        return {
            isLoad: false,

            news: {
                title: '',
                createdTime: '',
                typeDesc: '',
                contents: [],
                id: ''
                // NEWS_PIC: '',
                // NEWS_QR: ''
            },

            topBtnShow: 0,

            skin: {
                PROJECT_COLOR: ''
            },
            id:'',
        };
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: async function (options) {
        ProjectBiz.initPage(this);
        this.id = options.id;
		// debugger
        // if (!pageHelper.getOptions(this, options)) {
        //     return;
        // }
        this.loadDetailFun();
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {},
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: async function () {
        await this.loadDetailFun();
        uni.stopPullDownRefresh();
    },
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {},
    onPageScroll: function (e) {
        // 回页首按钮
        pageHelper.showTopBtn(e, this);
    },
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function (res) {
        return {
            title: this.news.title,
            imageUrl: this.news.cover
        };
    },
    methods: {
        loadDetailFun: async function () {
            let id = this.id;
            if (!id) {
                return;
            }
            let params = {
                id
            };
            let opt = {
                title: 'bar'
            };
            let news = await api.getNoticeDetail(id);
			// debugger
            if (!news) {
                this.setData({
                    isLoad: null
                });
                return;
            }
            this.setData({
                isLoad: true,
                news,
                topBtnShow: 1
            });
            FootBiz.addFootNew(news.id,3,news.title);
        },

        // getNewDetail: async function (params) {
        //     // mock数据
        //     console.log('getNewDetail', params);
        //     return {
        //         NEWS_TITLE: 'Mock 新闻标题',
        //         NEWS_ADD_TIME: '2025-07-12',
        //         NEWS_CATE_NAME: 'Mock 分类',
        //         NEWS_CONTENT: [
        //             {
        //                 type: 'text',
        //                 val: '这是模拟的新闻内容段落一。这是模拟的新闻内容段落二。这是模拟的新闻内容段落三。'
        //             },
        //             {
        //                 type: 'img',
        //                 val: '/static/images/news1.jpg'
        //             }
        //         ],
        //         _id: 'mock_id_001',
        //         NEWS_PIC: ['/static/images/news1.jpg'],
        //         NEWS_QR: '/static/images/qr.png'
        //     };
        // },
        url: function (e) {
            pageHelper.url(e, this);
        }
    }
};
</script>

<style>
@import './news_detail.css';
</style>